﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LGSVR_WEB
{
    public partial class login : LGSVR.Common.DataBasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, ImageClickEventArgs e)
        {

            string newPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text.Trim(), "SHA1");
            LGSVR.BLL.Sys.UserBLL userBll = new LGSVR.BLL.Sys.UserBLL();
            if (userBll.CheckLogin(txtUserName.Text.Trim(), newPwd, getIP()))
            {
                Dictionary<string, string> dicSingle = GetSigle("userInfo", "userid='" + txtUserName.Text.Trim() + "' and state<>'P'");
                Session["UserID"] = txtUserName.Text.Trim();
                Session["CompanyID"] = dicSingle["companyID"];
                Session["UserName"] = dicSingle["userName"];
                Session["actID"] = dicSingle["actID"]; //20120908 chengzb
                Session["ActName"] = GetSigle("userAct", "ActID='" + dicSingle["actID"].ToString() + "'")["ActName"];
                Response.Redirect("ExtMain.aspx", false);
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "aaa", "alert('登陆失败，请重试…');", true);
            }
        }
        //获取客户端IP地址 
        public string getIP()
        {
            string result = String.Empty;
            result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (null == result || result == String.Empty)
            {
                result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            if (null == result || result == String.Empty)
            {
                result = HttpContext.Current.Request.UserHostAddress;
            }
            if (null == result || result == String.Empty)
            {
                return "0.0.0.0";
            }
            return result;

        }

    }
}